package com.yxdj.ai.controller;

import com.yxdj.ai.service.AssistantService;
import dev.langchain4j.rag.content.Content;
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
import dev.langchain4j.rag.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/langchain4j")
public class LangChain4jController {

    @Autowired
    private AssistantService assistantService;

    @Autowired
    private EmbeddingStoreContentRetriever embeddingStoreContentRetriever;

    @RequestMapping("/chatToAi")
    public Flux<String> chatToAi(@RequestParam(value = "userId",required = false,defaultValue = "1") String userId,
                         @RequestParam(value = "message",required = false,defaultValue = "做个自我介绍") String message){
        List<Content> retrieve = embeddingStoreContentRetriever.retrieve(new Query(message));
        for (Content content : retrieve) {
            System.out.println("检索出的内容：" + content);
        }
        return assistantService.chatToAi(userId,message, LocalDate.now().toString());
    }

}
